#!/usr/bin/env python
"""
创建学部数据的脚本
"""
import os
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'educational_system.settings')
django.setup()

from apps.accounts.models import Department

def create_departments():
    """创建学部数据"""
    print("=== 创建学部数据 ===")
    
    departments_data = [
        {'name': 'engineering', 'description': '工程技术相关学科'},
        {'name': 'science', 'description': '自然科学相关学科'},
        {'name': 'humanities', 'description': '人文社会科学相关学科'},
        {'name': 'economics', 'description': '经济学相关学科'},
        {'name': 'management', 'description': '管理学相关学科'},
    ]
    
    created_count = 0
    for dept_data in departments_data:
        department, created = Department.objects.get_or_create(
            name=dept_data['name'],
            defaults={
                'description': dept_data['description']
            }
        )
        if created:
            created_count += 1
            print(f"创建学部: {department.get_name_display()}")
        else:
            print(f"学部已存在: {department.get_name_display()}")
    
    print(f"\n总共创建了 {created_count} 个学部")
    print(f"当前共有 {Department.objects.count()} 个学部")

if __name__ == '__main__':
    create_departments()